#pragma once

#ifndef MAINWND_H
#define MAINWND_H

#include <QtCore>
#include <QtGui>
#include <QtWidgets>

#include "ExtendWindow.h"

#include "webtabwidget.h"
#include "webwnd.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWnd; }
QT_END_NAMESPACE

class MainWnd : public ExtendWindow
{
    Q_OBJECT
public:
    inline static MainWnd* instance() { return ms_instance; }

protected:
    static MainWnd* ms_instance;   //

public:
    MainWnd(const QString & strUrl = "", QWidget *parent = nullptr);
    ~MainWnd();

public:
    WebWnd * newTab(const QString & strUrl = "", bool current = true, int index = -1);

    void loadUrl(const QUrl & url);
    void load(const QString & strUrl);

protected:
    virtual void firstShowedEvent(QEvent * event) override;
    virtual void closeEvent(QCloseEvent *event) override;

public:
    QString getFirstUrl() { return m_strFirstUrl; }
    void setFirstUrl(const QString & val) { m_strFirstUrl = val; }

protected:
    WebTabWidget *  m_tab;
    QString m_strFirstUrl;

    QMenu *     m_muMain;
    QAction *   m_atClose;

    QMenu *     m_muHelp;

protected:
    void init();
    void initMenu();

public slots:
    void onClose();

    void onNew();
    void onMenu();
    void onExit();
    void onMax();
    void onMin();

    void onAllTabClosed();

    void onNewMainWnd(QString strUrl);

private:
    Ui::MainWnd *ui;
};

//////////////////////////////////////////////////////////////////////////
//
inline MainWnd * mainWnd() { return MainWnd::instance(); }


#endif // MAINWND_H
